<!-- 用户列表 -->
<style>
	th {
		text-align: center;
	}
	
	.table>tbody>tr>td {
		line-height: 40px;
		text-align: center;
		height: 40px;
		margin: 0px auto;
	}
	#data_page .table>tbody>tr>td:last-child{
	text-align: center;
}
	font{ margin: 0px auto;}
	#myModal .modal-dialog {
		width: 80%;
	}
</style>
<div id="data_page" class="in_page">

	<div class="panel panel-default">
		<div class="panel-body">
			<form class="form-inline" method="get" name="keyword" id="keyword">

				<button type="button" class="btn btn-sm btn-default bs_type" status="">全部订单</button>
				<button type="button" class="btn btn-sm btn-primary bs_type" status="0">待付款订单</button>
				<button type="button" class="btn btn-sm btn-primary bs_type" status="1">待发货订单</button>
				<button type="button" class="btn btn-sm btn-primary bs_type" status="2">待收货订单</button>
				<button type="button" class="btn btn-sm btn-primary bs_type" status="3">待评价订单</button>
				<button type="button" class="btn btn-sm btn-primary bs_type" status="4">已完成订单</button>
				<button type="button" class="btn btn-sm btn-primary bs_type" status="5">已关闭订单</button>
				<div class="form-group">
					<input type="text" class="form-control" id="exampleInputName2" name="key" placeholder="订单编号">
				</div>
				<button type="submit" class="btn btn-sm btn-default">搜索</button>
			</form>
		</div>
	</div>

	<table class="table table-striped table-bordered table-condensed  ">
		<thead>
			<tr>
				<th>key</th>
				<th>订单号</th>
				<th>用户信息</th>

				<th>订单详情</th>
				<th>下单时间</th>
				<th>订单总价</th>
				<th>订单状态</th>
				<th>操作</th>

			</tr>
		</thead>
		<tbody>
			<volist name="list" id="li">
				<tr>
					<td>{$key+1}</td>
					<td>{$li.code}</td>
					<td style="line-height: 20px;">昵称：{$li.nickname}
						<br/>手机号：{$li.phone}</td>

					<td width="250px">
						<button type="button" class="btn btn-sm btn-success info" d_code="{$li.code}" data-toggle="modal" data-target="#myModal">订单详情</button>
					</td>
					<td>
						<?php echo date('Y-m-d H:i:s',$li['ctime'])?>
					</td>
					<td>￥{$li.cprice}</td>
					<td>
						<if condition="$li.status eq '0'">
							<font color="red">待付款</font>
							<elseif condition="$li.status eq '1'" />
							<font color="blue">待发货</font>
							<elseif condition="$li.status eq '2'" />
							<font color="green">待收货</font>
							<elseif condition="$li.status eq '3'" />
							<font color="green">待评价</font>
							<elseif condition="$li.status eq '4'" />
							<font color="green">已完成</font>
							<else/>
							<font color="black">交易关闭</font>
						</if>
					</td>
					<td width="100px">
						<if condition="$li.status eq '0'">
							<button type="button" class="btn btn-sm btn-danger Cancel" did="{$li.id}" p_type="del">取消订单</button>
							<button type="button" class="btn btn-sm btn-success confirm_pay" data-toggle="modal" data-target="#confirm_pay" data-order_id="{$li.id}">确认付款</button>
						<elseif condition="$li.status eq '1'" />
							<button type="button" class="btn btn-sm btn-success delivery" data-toggle="modal" data-target="#delivery" did="{$li.id}">发货</button>
						<elseif condition="$li.status eq '2'" />
							<button type="button" class="btn btn-sm btn-success Cancel" did="{$li.id}" p_type="ok">确认收货</button>
						<elseif condition="$li.status eq '3'" />
							<font color="black">待评价</font>
						<elseif condition="$li.status eq '4'" />
							<font color="black">交易完成</font>
						<else />
							<font color="black">交易关闭</font>
						</if>

					</td>
				</tr>
			</volist>
		</tbody>
	</table>
</div>
<div class="pageList">{$page}</div>

<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
	<div class="modal-dialog">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-hidden="true">
					&times;
				</button>
				<h4 class="modal-title" id="myModalLabel">
					订单号：
				</h4>
			</div>
			<div class="modal-body">
				<table class="table table-striped table-bordered table-condensed  ">
					<thead>
						<tr>
							<th>商品标题</th>
							<th>商品描述</th>
							<th>属性</th>
							<th>数量</th>
							<th>合计</th>
						</tr>
					</thead>
					<tbody id="orderinfo">

					</tbody>
				</table>
				<p class="infoname"></p>
				<p class="infophone"></p>
				<p class="muted"></p>
				<p class="infoprice"></p>
				<p class="logistics_code"></p>
				<p class="logistics_type"></p>
			</div>
			<div class="modal-footer">
				<button type="button" class="btn btn-default" data-dismiss="modal">关闭
				</button>

			</div>
		</div>
		<!-- /.modal-content -->
	</div>
	<!-- /.modal -->
</div>


<div class="modal fade" id="delivery" tabindex="-1" role="dialog" aria-labelledby="myModalLabela" aria-hidden="true">
	<div class="modal-dialog">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-hidden="true">
					&times;
				</button>
				<h4 class="modal-title" id="myModalLabela">发货</h4>
			</div>
			<div class="modal-body">
				<form id="bjy-form" class=" form-horizontal"  >
					<input type="hidden" class="form-control" id="orderid" />
					<div class="form-group">
					 <label for="title" class="col-sm-2 control-label" >物流/快递单号:</label>
					<div class="col-sm-6">
						<input type="text" class="form-control" id="logistics_code" />
					</div>
					</div>
					<div class="form-group">
					 <label for="title" class="col-sm-2 control-label" >物流/快递类型:</label>
					<div class="col-sm-6">
						<input type="text" class="form-control" id="logistics_type" />
					</div>
					</div>
					<div class="form-group">
					 <div class="col-sm-offset-2 col-sm-10">
						 <button type="button" class="btn btn-primary " id="button">提交</button>
					</div>
					</div>
				</form>
			</div>
			<div class="modal-footer">
				<button type="button" class="btn btn-default" data-dismiss="modal">关闭
				</button>

			</div>
		</div>
		<!-- /.modal-content -->
	</div>
	<!-- /.modal -->
</div>

<div class="modal fade" id="confirm_pay" tabindex="-1" role="dialog" aria-labelledby="myModalLabela1" aria-hidden="true">
	<div class="modal-dialog">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-hidden="true">
					&times;
				</button>
				<h4 class="modal-title" id="myModalLabela1">确认已付款</h4>
			</div>
			<div class="modal-footer">
				<button type="button" class="btn btn-primary" id="confirm_pay_btn">提交</button>
				<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
			</div>
		</div>
	</div>
</div>

<script>
	$(function() {

		$('.info').click(function() {
			var code = $(this).attr('d_code');
			$("#myModalLabel").text("订单号：" + code);
			var url = "{:U('Order/orderInfo')}";
			$.post(url, {
				code: code
			}, function(obj) {
				if(obj.s) {
					var data = obj.d;
					var html = "";
					$('#orderinfo').empty();
					$.each(data, function(i, d) {
						html += '<tr ><td >' + d.title + '</td><td >' + d.ds + '</td><td >' + d.attr + '</td><td >x' + d.num + '</td><td >￥' + d.price * d.num + '</td></tr>';
					})
					$('#orderinfo').append(html);
					$('.muted').text("收货人地址：" + obj.o.c_addr);
					$('.infoprice').text("总价：￥" + obj.o.cprice);
					$('.infophone').text("收货人联系方式：" + obj.o.c_phone);
					$('.infoname').text("收货人：" + obj.o.c_name);
					$('.logistics_code').text("物流/快递单号：" + obj.o.logistics_code);
					$('.logistics_type').text("物流/快递类型：" + obj.o.logistics_type);
				}
			})
		});
		$('.bs_type').click(function() {
			var type = $(this).attr('status');
			if(type == "") {
				location.href = "{:U('Order/index')}";
			} else {
				location.href = "{:U('Order/index')}?status=" + type;
			}
		});
		$('.Cancel').click(function() {
			var type = $(this).attr('p_type');
			var id=$(this).attr('did');
			if(type == "del") {
				location.href = "{:U('Order/Cancel')}?id="+id;
			} else {
				location.href = "{:U('Order/ok')}?id="+id;
			}
		})
		
		$('.delivery').click(function() {
			var id=$(this).attr('did');
			$("#orderid").val(id)
		})
		
		$('#button').click(function() {
			var id=$("#orderid").val();
			var logistics_code=$("#logistics_code").val()
			var logistics_type=$("#logistics_type").val()
			var url="{:U('Order/logistics')}";
			var data={
				id:id,
				logistics_code:logistics_code,
				logistics_type:logistics_type,
			}
			$.post(url,data,function(obj){
				if(obj.s){
					location.href = "{:U('Order/index')}";
				}
			})
		})
		$(".confirm_pay").click(function(){
			var id=$(this).data('order_id');
			$("#orderid").val(id)
		});
		$("#confirm_pay_btn").click(function(){
			var id=$("#orderid").val();
			$.post("{:U('confirm_pay')}", {id: id}, function(obj, textStatus, xhr) {
				if(obj.s){
					location.href = "{:U('Order/index')}";
				}else{
					alert(obj.m);
				}
			});
		})
	})
</script>